package controller;

import java.util.ArrayList;
import java.util.List;

import model.ItemProovedor;
import model.Proovedor;
import beans.ItemProovedorBean;
import beans.ProovedorBean;
import dao.HibernateProveedorDAO;
import dto.ItemProovedorDTO;
import dto.ProovedorDTO;

public class AdministradorProovedor {
	private static AdministradorProovedor instancia;

	private AdministradorProovedor() {

	}

	public static AdministradorProovedor getInstancia() {
		if (instancia == null)
			instancia = new AdministradorProovedor();
		return instancia;
	}

	public List<ItemProovedorBean> fromModelTOBean(
			List<ItemProovedor> proovedores) {
		List<ItemProovedorBean> proovedoresBean = new ArrayList<ItemProovedorBean>();
		for (ItemProovedor proovedor : proovedores) {
			ItemProovedorBean proovedorBean = this.fromModelTOBean(proovedor);
			proovedoresBean.add(proovedorBean);
		}
		return proovedoresBean;
	}

	public ItemProovedorBean fromModelTOBean(ItemProovedor proovedor) {
		ItemProovedorBean proovedorBean = null;
		if (proovedor != null) {
			proovedorBean = new ItemProovedorBean();
			proovedorBean.setIdItemProovedor(proovedor.getId());
			proovedorBean.setPrecio(proovedor.getPrecio());
			proovedorBean
					.setProovedor(fromModelTOBean(proovedor.getProovedor()));
		}
		return proovedorBean;
	}

	public ProovedorBean fromModelTOBean(Proovedor proovedor) {
		ProovedorBean proovedorBean = null;
		if (proovedor != null) {
			proovedorBean = new ProovedorBean();
			proovedorBean.setIdProveedor(proovedor.getId());
			proovedorBean.setNombre(proovedor.getNombre());
		}
		return proovedorBean;
	}

	public List<ItemProovedor> fromDTOTOModel(
			List<ItemProovedorDTO> proovedoresDTO) {
		List<ItemProovedor> proovedores = new ArrayList<ItemProovedor>();
		for (ItemProovedorDTO proovedorDTO : proovedoresDTO) {
			ItemProovedor proovedor = this.fromDTOTOModel(proovedorDTO);
			proovedores.add(proovedor);
		}
		return proovedores;
	}

	public ItemProovedor fromDTOTOModel(ItemProovedorDTO proovedorDTO) {
		ItemProovedor proovedor = null;
		if (proovedorDTO != null) {
			proovedor = new ItemProovedor();
			proovedor.setId(proovedorDTO.getId());
			proovedor.setPrecio(proovedorDTO.getPrecio());
			proovedor.setProovedor(fromDTOTOModel(proovedorDTO.getProovedor()));
		}
		return proovedor;
	}

	public Proovedor fromDTOTOModel(ProovedorDTO proovedorDTO) {
		Proovedor proovedor = null;
		if (proovedorDTO != null) {
			proovedor = new Proovedor();
			proovedor.setId(proovedorDTO.getId());
			proovedor.setNombre(proovedorDTO.getNombre());
		}
		return proovedor;
	}

	public List<ItemProovedorDTO> fromModelTODTO(List<ItemProovedor> proovedores) {
		List<ItemProovedorDTO> proovedoresDTO = new ArrayList<ItemProovedorDTO>();
		for (ItemProovedor proovedor : proovedores) {
			ItemProovedorDTO proovedorDTO = this.fromModelTODTO(proovedor);
			proovedoresDTO.add(proovedorDTO);
		}
		return proovedoresDTO;
	}

	public ItemProovedorDTO fromModelTODTO(ItemProovedor proovedor) {
		ItemProovedorDTO proovedorDTO = null;
		if (proovedor != null) {
			proovedorDTO = new ItemProovedorDTO();
			proovedorDTO.setId(proovedor.getId());
			proovedorDTO.setPrecio(proovedor.getPrecio());
			proovedorDTO.setProovedor(fromModelTODTO(proovedor.getProovedor()));
		}
		return proovedorDTO;
	}

	public ProovedorDTO fromModelTODTO(Proovedor proovedor) {
		ProovedorDTO proovedorDTO = null;
		if (proovedor != null) {
			proovedorDTO = new ProovedorDTO();
			proovedorDTO.setId(proovedor.getId());
			proovedorDTO.setNombre(proovedor.getNombre());
		}
		return proovedorDTO;
	}

	public List<ItemProovedor> fromBeanTOModel(
			List<ItemProovedorBean> proovedoresBean) {
		List<ItemProovedor> proovedores = new ArrayList<ItemProovedor>();
		for (ItemProovedorBean proovedorBean : proovedoresBean) {
			ItemProovedor proovedor = this.fromBeanTOModel(proovedorBean);
			proovedores.add(proovedor);
		}
		return proovedores;
	}

	public ItemProovedor fromBeanTOModel(ItemProovedorBean proovedorBean) {
		ItemProovedor proovedor = null;
		if (proovedorBean != null) {
			proovedor = new ItemProovedor();
			proovedor.setId(proovedorBean.getIdItemProovedor());
			proovedor.setPrecio(proovedorBean.getPrecio());
			proovedor
					.setProovedor(fromBeanTOModel(proovedorBean.getProovedor()));
		}
		return proovedor;
	}

	public Proovedor fromBeanTOModel(ProovedorBean proovedorBean) {
		Proovedor proovedor = null;
		if (proovedorBean != null) {
			proovedor = new Proovedor();
			proovedor.setId(proovedorBean.getIdProveedor());
			proovedor.setNombre(proovedorBean.getNombre());
		}
		return proovedor;
	}

	public Proovedor buscarProveedor(Proovedor proveedor) {
		ProovedorBean prob = fromModelTOBean(proveedor);
		prob = HibernateProveedorDAO.getInstancia().getProveedor(prob);
		return fromBeanTOModel(prob);
	}

	public List<Proovedor> _fromBeanTOModel(List<ProovedorBean> provsBean) {
		List<Proovedor> provs = new ArrayList<Proovedor>();
		for (ProovedorBean provBean : provsBean) {
			provs.add(fromBeanTOModel(provBean));
		}
		return provs;
	}

	public List<ProovedorDTO> fromModelToDTO(List<Proovedor> provs) {
		List<ProovedorDTO> provDTO = new ArrayList<ProovedorDTO>();
		for (Proovedor prov : provs) {
			provDTO.add(fromModelTODTO(prov));
		}
		return provDTO;
	}

	public List<Proovedor> listProveedores() {
		List<ProovedorBean> provBeans = HibernateProveedorDAO.getInstancia()
				.list();
		return _fromBeanTOModel(provBeans);
	}
}
